<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
            
                <ul class="list">
                    <li>1</li>
                    <li>2</li>
                    <li>3</li>
                    <li>4</li>
                    <li>5</li>
                </ul>
   




   
    
</body>

<script>
          window.onload=  function (){

                // var ul = document.getElementsByClassName("list")[0];
                //    var ul_child = ul.getElementsByTagName('li');
                var ul_child = document.getElementsByTagName('li');
                   for (var i = 0; i < ul_child.length; i++) {
                       ul_child[i].index = i;
                       ul_child[i].onclick = function(){
                           var j = this.index;
            　               alert("元素索引为" +this.index);
            }
        }
    }
      
                
</script>
</html>